# -*- coding:utf-8 -*-
__author__ = 'gxb'
import  json
from DbUtile import *
from xpinyin import Pinyin
import codecs


#json file:
#The file content of temp.json is:
#{
# "name":"00_sample_case1",
# "description":"an example."
#}
#f = file("temp.json");
#s = json.load(f)
#print s
#f.close

#json string:
s = json.loads('{"name":"test", "type":{"name":"seq", "parameter":["1", "2"]}}')
# print s
# print s.keys()
# print s["name"]
# print s["type"]["name"]
# print s["type"]["parameter"][1]

if __name__ == '__main__':
    # saveProvince('zz')
    prefix = 'student_type'
    f = file("d:/"+prefix+".json");
    s = json.load(f,encoding="utf-8");
    # for i in range(0,len(s)-1):
    for i in range(0,len(s)-1):
        pName = s[i]['value']
        p = Pinyin()
        # default splitter is `-`
        print(pName)
        id = i+1

        key = '%s.%s_%s' % (prefix,p.get_pinyin(pName,''),id)
        keyValue = '%s=%s' % (key,pName)

        saveStudentType(key,pName)
        #追加方式写文件
        f2=codecs.open('d:/'+prefix+'.properties',"a","utf-8")
        f2.write(keyValue + "\n")
        f2.close()


    f.close